package com.espirit.init.base;

import org.springframework.stereotype.Component;

import com.espirit.eap.manager.Department;
import com.espirit.eap.manager.ModelBuilderSupport;
import com.espirit.eap.pagelayout.ModelField;
import com.espirit.eap.relationship.PartyRelationship;
@Component
public class DepartmentBuilder extends ModelBuilderSupport {
	private static final String FIELD_CODE="code";
	private static final String FIELD_NAME="name";
	@Override
	public boolean init() {
		return super.setClass(Department.class, "Department", "部门") ;
	}
	@Override
	public void buildFields() {
		addModelField(FIELD_CODE, "Code", "代码");
		addModelField(FIELD_NAME, "Name", "名称");
	}
	@Override
	public void prepareLayoutElements() {
		ModelField mfName = getModelField(FIELD_NAME);
		ModelField mfCode = getModelField(FIELD_CODE);
		
		addListField(mfCode,mfName);
		addDetailField(mfCode,mfName);
		setRequired(FIELD_CODE);
		setRequired(FIELD_NAME);
		
		super.prepareLayoutElements();
	}
	@Override
	public void initDefaultData() {
//		Department root = new Department();
//		root.setName("公司");
//		root = addDepartment(root, null);
//		super.initDefaultData();
	}
	
//	private Department addDepartment(Department department,Department parent){
//		department = addModel(department);
//		PartyRelationship prs = new PartyRelationship();
//		prs.setPartyChild(department);
//		prs.setPartyParent(parent);
//		department.safeGetParents().add(prs);
//		
//		genericService.update(department);
//		
//		return department;
//	}
	
}
